package com.lcubigdata.service.impl;

import com.lcubigdata.dao.UserDao;
import com.lcubigdata.dao.impl.UserDaoImpl;
import com.lcubigdata.pojo.User;
import com.lcubigdata.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Component
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    public List<User> findAll() {
        List<String> lines=userDao.findAll();

        List<User> userlist =lines.stream().map(line -> {
            String[] split = line.split(",");
            Integer id=Integer.parseInt(split[0]);
            String username=split[1];
            String password=split[2];
            String name=split[3];
            Integer age=Integer.parseInt(split[4]);
            LocalDateTime updateTime=LocalDateTime.parse(split[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new User(id,username,password,name,age,updateTime);
        }).toList();

        return userlist;
    }


}
